<p>The <code>java.util.Collection</code> API has methods that accept <code>Object</code> parameters such as <code>Collection.remove(Object o)</code>,
and <code>Collection.contains(Object o)</code>. When the actual type of the object provided to these methods is not consistent with the type declared
on the <code>Collection</code> instantiation, those methods will always return <code>false</code> or <code>null</code>. This is most likely unintended
and hides a design problem.</p>
<p>This rule raises an issue when the type of the argument of the following APIs is unrelated to the type used for the <code>Collection</code>
declaration:</p>
<ul>
  <li> <code>Collection.remove(Object o)</code> </li>
  <li> <code>Collection.removeAll(Collection&lt;?&gt;)</code> </li>
  <li> <code>Collection.contains(Object o)</code> </li>
  <li> <code>List.indexOf(Object o)</code> </li>
  <li> <code>List.lastIndexOf(Object o)</code> </li>
  <li> <code>Map.containsKey(Object key)</code> </li>
  <li> <code>Map.containsValue(Object value)</code> </li>
  <li> <code>Map.get(Object key)</code> </li>
  <li> <code>Map.getOrDefault(Object key, V defaultValue)</code> </li>
  <li> <code>Map.remove(Object key)</code> </li>
  <li> <code>Map.remove(Object key, Object value)</code> </li>
</ul>
<h2>Noncompliant Code Example</h2>
<pre>
public class S2175 {

  public static void main(String[] args) {
    String foo = "42";
    Map&lt;Integer, Object&gt; map = new HashMap&lt;&gt;();
    map.remove(foo); // Noncompliant; will return 'null' for sure because 'map' is handling only Integer keys

    // ...

    List&lt;String&gt; list = new ArrayList&lt;String&gt;();
    Integer integer = Integer.valueOf(1);
    if (list.contains(integer)) { // Noncompliant; always false.
      list.remove(integer); // Noncompliant; list.add(integer) doesn't compile, so this will always return 'false'
    }
  }

}
</pre>
<h2>See</h2>
<ul>
  <li> <a href="https://wiki.sei.cmu.edu/confluence/x/uDdGBQ">CERT, EXP04-J.</a> - Do not pass arguments to certain Java Collections Framework methods
  that are a different type than the collection parameter type </li>
</ul>

